//
//  OrderManagerController.m
//  YongChuanTradingArea
//
//  Created by 李冰 on 2017/9/13.
//  Copyright © 2017年 李冰. All rights reserved.
//

#import "OrderManagerController.h"
#import "OrderManagerListView.h"
#import "LBSegmentControl.h"
#import "OrderManagerListView.h"
#import "OrderManagerSearchView.h"

@interface OrderManagerController ()<UIScrollViewDelegate>

@property (nonatomic, strong) UIScrollView *contentView;

@end

@implementation OrderManagerController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"订单管理";
    
//    OrderManagerSearchView *search = [[NSBundle mainBundle] loadNibNamed:@"OrderManagerSearchView" owner:nil options:nil].lastObject;
//    search.frame = CGRectMake(0, 0, lbScreenWidth, 45);
//    [self.view addSubview:search];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    LBSegmentControl *segment = [[LBSegmentControl alloc] initWithFrame:CGRectMake(0, 1, lbScreenWidth, 60)];
    segment.backgroundColor = kWhiteColor;
    segment.showCount = 4;
    segment.normalFont = 14;
    segment.selectFont = 14;
    segment.normalColor = [UIColor colorWithHex:0x666666];
    segment.selectedColor = [UIColor colorWithHex:0x13be5a];
    segment.trunkTintColor = [UIColor colorWithHex:0x13be5a];
    segment.showBottomLine = YES;
    segment.lineWidth = 25;
    segment.items = @[@"待消费", @"待退款", @"已取消", @"已消费", ];
    [segment addTarget:self action:@selector(segmentAction:)];
    [self.view addSubview:segment];
    
    [self.view addSubview:self.contentView];
    CGFloat W = lbScreenWidth;
    CGFloat H = lbScreenHeight - 61 - 64;
    for (int i = 0; i < 4; i++)
    {
        OrderManagerListView *list = [[OrderManagerListView alloc] initWithFrame:CGRectMake(i * W, 0, W, H) type:i+1];
        if (i == 0)
        {
            [list willShow];
        }
        list.tag = i + 1;
        [self.contentView addSubview:list];
    }
    self.contentView.contentSize = CGSizeMake(4 * W, 0);
    
}

- (UIScrollView *)contentView {

    if (_contentView) return _contentView;
    
    _contentView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 61, lbScreenWidth, lbScreenHeight - 61 - 64)];
    _contentView.delegate = self;
    _contentView.pagingEnabled = YES;
    
    return _contentView;
}

- (void) segmentAction:(LBSegmentControl *) sender {

    [self.contentView setContentOffset:CGPointMake(sender.selectedSegmentIndex * lbScreenWidth, 0) animated:YES];
    OrderManagerListView *list = [self.contentView viewWithTag:sender.selectedSegmentIndex + 1];
    [list willShow];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {

    NSInteger tag = scrollView.contentOffset.x / lbScreenWidth + 1;
    
    OrderManagerListView *list = [self.contentView viewWithTag:tag];
    [list willShow];
}

@end
